#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e5+10;

int n,cnt,h[N],S,q,deg[N];
struct edge{int v,w,nxt;}e[N<<1];
void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;}

struct Tree{
	int md[N],f[22][N],g[22][N],son[N],top[N],rt,d[N],tot,p[N],rk[N],per[N],s[N];
	
	void dfs1(int x,int p){
		for(int i = h[x],y;i;i = e[i].nxt) if((y = e[i].v) != p) d[y] = d[x] + e[i].w,dfs1(y,x);
	}
	
	void dfs2(int x){
		for(int i = h[x],y;i;i = e[i].nxt)
			if((y = e[i].v) != f[0][x]){
				f[0][y] = x; g[0][y] = e[i].w;
				for(int j = 1;j < 22;j++) f[j][y] = f[j-1][f[j-1][y]] , g[j][y] = g[j-1][y] + g[j-1][f[j-1][y]];
				dfs2(y); if(md[y] + e[i].w > md[x]) son[x] = y,md[x] = md[y] + e[i].w;
			}
		for(int i = h[x],y;i;i = e[i].nxt){
			if((y = e[i].v) != son[x] && y != f[0][x]){
				p[++tot] = y; s[y] = md[y] + e[i].w;
			}
		}
	}
	
	void getrt(int x){
		dfs1(x,0); rt = x;for(int i = 1;i <= n;i++) if(d[i] > d[rt]) rt = i;
		dfs2(rt); p[++tot] = rt; s[rt] = md[rt];
		auto cmp = [&](int x, int y) -> bool {
			return s[x] > s[y];
		};
		sort(p+1,p+tot+1,cmp); for(int i = 1;i <= tot;i++) per[i] = per[i-1] + s[p[i]];
		for(int i = 1;i <= tot;i++){
			int t = p[i]; while(t) top[t] = p[i],rk[t] = i,t = son[t];
		}
	}

	int ans1(int x,int y){
		int tmp = md[x];
		for(int i = 21;~i;i--) if(rk[f[i][x]] >= y) tmp += g[i][x],x = f[i][x];
		return per[y-1] + g[0][x] + tmp;
	}

	int ans2(int x,int y){
		int tmp = md[x];
		for(int i = 21;~i;i--) if(rk[f[i][x]] > y) tmp += g[i][x],x = f[i][x];
		return per[y] - md[f[0][x]] + g[0][x] + tmp;
	}

	int ask(int x,int y){
		y = y << 1; y--; return y >= rk[x] ? per[y] : max(ans1(x,y) , ans2(x,y));
	}
}tr[2];
	
int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; q = in; for(int i = 1,u,v,w;i < n;i++) u = in,v = in,w = in,S+=w,link(u,v,w),link(v,u,w),deg[u]++,deg[v]++;
	int k = 0; for(int i = 1;i <= n;i++) k += deg[i] == 1; tr[0].getrt(1); tr[1].getrt(tr[0].rt);
	int ans = 0;
	while(q--){int x = (in+ans-1)%n+1,y = (in+ans-1)%n+1;ans = y * 2 >= k ? S : max(tr[0].ask(x,y),tr[1].ask(x,y)); printf("%lld\n",ans);}
	return 0;
}
